<style scoped>
</style>
<template>
    <div class="mui-content books-list-content" id="content">

      <img src="../assets/img/bg.png" width="100%" alt="">

    </div>
</template>
<script>

    import util from '@/fetch/util';


    export default {
        data () {
            return {
              subjects: {},
              code:''
            }
        },
        methods: {
            getToken(code){
                let $this = this;
                let params = {
                    code:code
                };

                util.fetchPost(util.path.wxGetToken, params).then((data) => {
                  //控制加载条

                  if (data) {

                    localStorage.setItem("lng-user", data.data);
                    if (data.token){
                        localStorage.setItem("lng-token", data.token);
                      this.$router.push({path: '/amap'})

                    }else {
                      this.$router.push({path: '/login'})

                    }

                  }

                }).catch(err => {
                  this.$vux.loading.hide();
                  this.$vux.toast.text(err.message)
                })
            },
        },
        mounted(){
          let $this = this;
          localStorage.removeItem("lng-token");

          if ($this.$route.query.code){
              $this.code = $this.$route.query.code;

          }else {
              $this.code = window.location.href.match(/=(\S*)&/)[1];
          }
          $this.getToken($this.$route.query.code);


        }
    }

</script>
